home *** CD-ROM | disk | FTP | other *** search
/ ftp.mactech.com 2010 / ftp.mactech.com.tar / ftp.mactech.com / machack / Hacks97 / WarriorsProgress.sit / Warrior’s Progress / source code / Source / Libraries / Heap / HeapLink.h < prev    next >
Text File  |  1997-06-28  |  1KB  |  51 lines

  1. // HeapLink.h
  2.  
  3. #ifndef HeapLink_h
  4. #define HeapLink_h
  5.  
  6. #ifndef Integers_h
  7. #include "Integers.h"
  8. #endif
  9. #ifndef Assert_h
  10. #include "Assert.h"
  11. #endif
  12.  
  13. template < class Element > class Heap;
  14.  
  15. template < class Element >
  16. class HeapLink
  17.   {
  18.     typedef Element ElementType;
  19.     typedef HeapLink< Element > LinkType;
  20.     typedef Heap< Element > HeapType;
  21.     typedef bool (ElementType::*Comparator)( const Element& ) const;
  22.     
  23.     friend class Heap< Element >;
  24.     
  25.     private:
  26.         Element *body;
  27.         HeapType *heap;
  28.         uint32 path;
  29.         LinkType *children[2];
  30.     
  31.         void SwapWith( LinkType& );
  32.         bool operator<=( const LinkType& ) const;
  33.         bool operator>( const LinkType& r ) const    { return !( *this <= r ); }
  34.         
  35.     public:
  36.         HeapLink( Element *e = 0 );
  37.         ~HeapLink();
  38.         
  39.         bool Listed() const                        { return heap != 0; }
  40.         HeapType& Heap() const                    { Assert( heap != 0 ); return *heap; }
  41.         
  42.         bool Null() const                            { return body == 0; }
  43.         Element *Target() const                    { return body; }
  44.         void PointTo( Element *b )                { body = b; }
  45.  
  46.         Element& operator*() const                { Assert( body != 0 ); return *body; }
  47.         Element *operator->() const            { Assert( body != 0 ); return body; }
  48.   };
  49.  
  50. #endif
  51.